<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <link rel="stylesheet" href="./bootstrap/css/bootstrap.css">
</head>
<body>
    <div id="app">
        
        
       
       <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">添加品牌</h3>
                </div>
           <div class="panel-body form-inline">
            <label>
                    id
                    <input type="text" class="form-control" v-model="id">
            </label>
            <label>
                    name
                    <input type="text" class="form-control" v-model="name">
            </label>
            <button class="btn btn-primary" @click="add">添加</button>
           </div>
       </div>
       

        <table class="table">
            <thead>
                <tr>
                    <th>id</th>
                    <th>name</th>
                    <th>ctime</th>
                    <th>del</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in arr" :key="item.id">
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.ctime}}</td>

                    <td><a href="" @click.prevent="del(item.id)">删除</a></td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
    new Vue({
        el:"#app",
        data:{
            arr:[
                {id:"1",name:"奔驰",ctime:new Date()},
                {id:"2",name:"宝马",ctime:new Date()},
                {id:"3",name:"奥迪",ctime:new Date()}
            ],
            id:"",
            name:""
        },
        methods:{
            add(){
                var str={
                    id:this.id,name:this.name,ctime:new Date()
                }
            this.arr.push(str)
            this.id=this.name="";
            },
            del(id){
                this.arr.some((item,i)=>{
                    if(item.id==id){
                        this.arr.splice(i,1)
                        return true;
                    }
                })
                
            }
        }
    })
    
    </script>
    
</body>
</html>